package com.service.business.base.controller;


import com.service.business.base.controller.req.VerifyCodeReq;
import com.service.business.base.enums.SmsTypeEnum;
import com.service.business.base.service.VerifyCodeService;
import com.service.business.member.controller.req.TwoFaReq;
import com.service.business.utils.IpAddressUtil;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController()
@RequestMapping("/verify")
@Api(tags = "验证码发送类，需要登陆")
public class AuthVerifyCodeController extends BaseController {


    @Autowired
    private VerifyCodeService verifyCodeService;

    @ApiOperation("验证码发送接口")
    @GetMapping("/send/{codeType}")
    public BaseResponse sendVerifyCode(@PathVariable("codeType") String codeType, HttpServletRequest request) {
        SmsTypeEnum typeEnum = SmsTypeEnum.valueOf(codeType);
        if (typeEnum == null) {
            throw new IllegalArgumentException("No matching constant for [" + typeEnum + "]");
        }
        VerifyCodeReq verifyCodeReq = new VerifyCodeReq();
        verifyCodeReq.setIpAdd(IpAddressUtil.get(request));
        verifyCodeReq.setCodeType(typeEnum);
        verifyCodeService.commonSend(verifyCodeReq);
        return successQueryBaseResponse();
    }
}
